package com.demo.juc.lock;

/**
 * @Author: jxm
 * @Description: 可重入锁
 * @Date: 2024-2-5 16:00
 * @Version: 1.0
 */
public class ReenterLockDemo {

    static class Phone{
        public synchronized void sms(){
            System.out.println(Thread.currentThread().getName() + "sms");
            call(); //这里也有锁(sms锁里面的call锁)
        }
        public synchronized void call(){
            System.out.println(Thread.currentThread().getName() + "call");
        }
    }

    public static void main(String[] args) {
        Phone phone = new Phone();

        new Thread(()->{
            phone.sms();
        },"a").start();


        new Thread(()->{
            phone.sms();
        },"b").start();

    }

}
